<?php
namespace app\index\model;

use \think\Model;

class Vercode extends Model
{
    public function getRand()
    {
//        $sql = "select * from vercode order by rand() limit 1";
//        $data = $this->query($sql);
//
//         $info = Vercode::order('rand()')->limit(1)->select();
        $info = $this->order('rand()')->limit(1)->select();
         $data = current($info);
         session('answer', $data['answer']);
         return $data['question'];
    }

    public function checkCode($code)
    {
        if ($code == session('answer')){
            return true;
        }else{
            exit(json_encode(['error'=>1,'info'=>'验证码错误']));
        }
    }
}